import Vue from 'vue';
import Router from 'vue-router';
import home from './modules/home';
import menuDemo from './modules/menuDemo';

Vue.use(Router);

// constantRoutes
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},
{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
}
];

// asyncRoutes
export const asyncRoutes = [home, menuDemo];

// redirectPage
export const redirectPage = {
  path: '*',
  redirect: '/404',
  hidden: true
};

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

const router = createRouter();
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
  router.options.routes = constantRoutes;
  window.currentUserRouters = [];
  window.location.reload(true);
}

export default router;
